package com.sky.shop.controller;

import com.sky.constant.MessageConstant;
import com.sky.dto.ShopDTO;
import com.sky.entity.Shop;
import com.sky.result.Result;
import com.sky.shop.service.ShopService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Objects;

/**
 * 店铺管理 controller
 */
@Slf4j
@Api(tags = {"店铺管理"}, description = "后台店铺管理")
@RestController
@RequestMapping("/admin/shop")
public class ShopController {


    @Resource
    private ShopService shopService;



    /**
     * 店铺管理
     *        修改店铺营业状态
     * @param status
     */
    @ApiOperation(tags = {"店铺管理"}, value = "店铺营业/打烊修改", notes = "修改店铺营业状态")
    @PutMapping("/{status}")
    public Result updateShopStatus(@PathVariable(name="status")Integer status, Long id, String shopName){
        log.info("店铺管理 - 店铺id: {},店铺名称: {},修改店铺状态为: {}", id, shopName, status==1 ? "营业中" : "打烊");
        // 封装数据
        ShopDTO shopDTO = new ShopDTO();
        shopDTO.setId(id);
        shopDTO.setShopName(shopName);
        shopDTO.setShopStatus(status);
        // 调方法
        shopService.updateShopStatus(shopDTO);
        return Result.success();
    }



    /**
     * 店铺管理
     *        查询店铺营业状态   本项目默认只有这个店铺，所以参数都是可选
     */
    @ApiOperation(tags = {"店铺管理"}, value = "营业状态", notes = "查询店铺营业状态")
    @GetMapping("/status")
    public Result getShopStatus(Long id, String shopName){
        log.info("店铺管理 - 店铺id: {},店铺名称: {}, 查询店铺状态", id, shopName);
        // 封装数据，查询店铺状态
        Shop shop = Shop.builder().id(id).shopName(shopName).build();
        Integer shopStatus = shopService.selectShopStatus(shop);
        if(Objects.nonNull(shopStatus)){
            return Result.success(shopStatus);
        }
        return Result.error(MessageConstant.SHOP_STATUS_ERROR);
    }






}
